package wiki;

import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Iterator;

public class WikiDataTest {
    public static void main(String[] args) {
        try {
            String wikidata = FileUtils.readFileToString(new File("C:\\Users\\40138\\Desktop\\wikidata.txt"), StandardCharsets.UTF_8);
//            System.out.println(wikidata);
            ObjectMapper mapper = new ObjectMapper();
//            配置文本中允许出现 unescaped control characters
            mapper.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true);
            JsonNode recordJsonNode = mapper.readerFor(JsonNode.class).readTree(wikidata);
            String text = recordJsonNode.get("text").asText();
            String[] split = text.split("\n");
            Iterator<String> iterator = Arrays.stream(split).iterator();
            while (iterator.hasNext()) {
                String str = iterator.next();
                System.out.println(str);
            }
//            System.out.println(text);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
